import requests
import natsort
import os
path ='..\htmllist'
for i in range(15,90):
    url = 'your want to spider url...'

    # r = requests.get(url)
    try:
        r = requests.get(url)
        r.encoding = 'utf-8'
        # print(r.text)
        if r.text:
            with open(path+r'\url'+str(i),'wb') as handle:
                handle.write(r.content)
                handle.flush()
            handle.close()
        else:
            print(f'{url}未正常打开或者无内容')
            continue
    except Exception as e:
        print(e)
print('文件已保存完毕')
print('请问是否需要修改文件名')
print('请输入')
flag = input('1:修改 2:不修改')
if flag =='1':
    usr_fname = input('请输入需要修改的文件名的后缀名')
    filelist = natsort.natsorted(os.listdir(path))
    os.chdir(path)
    for filename in filelist:
        fin_name = filename+usr_fname
        if filename != fin_name:
            os.rename(filename, fin_name)
        else:
            print('文件已存在')
            pass
    print('successful')
elif flag == '2':
    print('不做任何修改')
else:
    print('faild')